import { fileURLToPath, URL } from 'node:url';
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
import vue2 from '@vitejs/plugin-vue2';

// https://cn.vitejs.dev/config/
export default defineConfig({
  plugins: [vue2()],
  base: process.env.NODE_ENV === 'development'?'/':'/',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    rollupOptions: {
      input: {
        main: resolve(__dirname, 'index.html')
      },
    },
  },
  server: {
    hmr:true,
    port: 9005, // 端口号
      host: 'localhost',
      https: false, // https:{type:Boolean}
      open: true, //配置自动启动浏览器 
      proxy: {
          '/api': {
            target: 'http://localhost:5293',
            // target: 'http://47.98.58.92:5293',
            changeOrigin: true,//允许跨域
            secure:false,//解决自签名证书错误
            rewrite: (path) => path.replace(/^\/api/, ''),
          },
          '/host': {
            target: 'http://localhost:5294',
            // target: 'http://47.98.58.92:5294',
            changeOrigin: true,//允许跨域
            secure:false,//解决自签名证书错误
            rewrite: (path) => path.replace(/^\/host/, ''),
          }
      }
  },
  css: {
    preprocessorOptions: {
      less: {
        additionalData: '@import "./src/assets/themes/style.less";'
      }
    }
  }
});
